package mock;

import org.apache.catalina.startup.Tomcat;

import java.io.File;

/**
 *
 * @author vladimir 03.09.2013   14:23
 */
public class Launcher {

    private Launcher() {}

    private static Launcher instance = new Launcher();

    public static Launcher getInstance() {
        return instance;
    }

    private int run() {
        try {

            String webappDirLocation = "web/";
            System.out.println("configuring app with basedir: " + new File(webappDirLocation).getAbsolutePath());
            Tomcat tomcat = new Tomcat();
            tomcat.setPort(8080);
            tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());

            tomcat.start();
            tomcat.getServer().await();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return 0;
    }

    public static void main(String args[]) {
        getInstance().run();
    }
}
